import sqlite3


class SQLiteDB:
    def __init__(self, db_name='./db/sqlite/faces.db'):
        self.conn = sqlite3.connect(db_name)
        self.cursor = self.conn.cursor()

    # 执行改变数据库的语句
    def execute(self, sql, parameters=None):
        if parameters:
            self.cursor.execute(sql, parameters)
        else:
            self.cursor.execute(sql)
        self.conn.commit()

    # 执行查询语句
    def fetch(self, sql, parameters=None):
        if parameters:
            self.cursor.execute(sql, parameters)
        else:
            self.cursor.execute(sql)
        rows = self.cursor.fetchall()
        return rows

    def close(self):
        self.cursor.close()
        self.conn.close()
